Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

138
Views
¿Cuál es el método equivalente para .pack("H*")].pack("m0") de Ruby en Javascript?

En Ruby, uso la función .pack("H*")].pack("m0") para codificar una cadena de mensaje hexadecimal en una cadena base64.

ex.

 msg_hex = 8308862831031591345F010101020663602A06E300000000EF934E0C5B29E50E000000000000000000000310000000004F04010000010000 msg_hex.pack("H*")].pack("m0") => gwiGKDEDFZE0XwEBAQIGY2AqBuMAAAAA75NODFsp5Q4AAAAAAAAAAAAAAxAAAAAATwQBAAABAAA=

En Javascript, estoy buscando un método equivalente para convertir el mensaje en un mensaje de base 64. Algunas respuestas indican Buffer.from(msg_hex).toString('base64') , pero el resultado es diferente.

 const msg_hex = 8308862831031591345F010101020663602A06E300000000EF934E0C5B29E50E000000000000000000000310000000004F04010000010000 Buffer.from(msg_hex).toString('base64') // => ODMwODg2MjgzMTAzMTU5MTM0NUYwMTAxMDEwMjA2NjM2MDJBMDZFMzAwMDAwMDAwRUY5MzRFMEM1QjI5RTUwRTAwMDAwMDAwMDAwMDAwMDAwMzEwMDAwMDAwMDA0RjA0MDAwMDAwMDEwMDAw

¿Cuál es el método equivalente para .pack("H*")].pack("m0") de Ruby en Javascript?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Casi llegaste con lo que proporcionaste.

Simplemente olvidó decirle a Buffer.from lo que estaba proporcionando, por defecto, si envía una cadena, solo la almacenará como una cadena. Pero lo que quería era decodificar la fuente como hexadecimal y luego almacenarla como binario.

Haciendo eso ->

 Buffer.from(msg_hex, 'hex').toString('base64')

IOW: te acabas de perder el segundo parámetro hex ..

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!